package com.czz.manage.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.czz.common.exception.ResultCodeEnum;
import com.czz.common.vo.R;
import com.czz.manage.entity.Order;
import com.czz.manage.query.OrderQuery;
import com.czz.manage.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: OrderAdminController
 * @Author Czz
 * @Date 2020/2/17
 * @Time 20:26
 **/
@RestController
@RequestMapping(value = "/admin/orders")
public class OrderAdminController {

    @Autowired
    OrderService orderService;


    /**
    * @Description 分页查询所有订单
    * @Param [page, limit, orderQuery]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/2/18
    * @Time 10:11
    **/
    @GetMapping(value = "/{page}/{limit}")
    public R getOrderPageList(@PathVariable Long page, @PathVariable Long limit, OrderQuery orderQuery){
        if (page <= 0 || limit <= 0){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        Page<Order> pageParam = new Page<>(page, limit);
        orderService.getOrderPageList(pageParam,orderQuery);
        List<Order> records = pageParam.getRecords();
        Long total = pageParam.getTotal();
        return R.ok().data("total", total).data("rows", records);
    }
}
